<template>
  <div class="will-packet">
    <div class="will-packet__bg"></div>
    <div class="will-packet__content">
      <span class="close" @click="closePacket">x</span>
      <div class="will-packet-top">
        <div class="will-packet__head">
          <img src="../../../static/imgs/finger.png" alt="">
        </div>
        <div class="will-packet__name">金手指</div>
        <div class="will-packet__p">给你发了一个红包</div>
        <div class="will-packet__title">恭喜发财，大吉大利</div>
      </div>
      <div class="will-packet__animation">
        <div class="will-packet__an__top">
          <div class="will-packet__an__inner" :class="{arcanimateTop: openAn}"></div>
        </div>
        <div class="will-packet__an__bottom" :class="{arcanimateBottom: openAn}"></div>
      </div>
      <div v-if="open" class="will-packet__open" :class="{rotateAn: rotateAn}" @click="openPacket">開</div>
      <div v-else class="will-packet__open" :class="{rotateAn: rotateAn}" @click="closePacket">関</div>
    </div>
  </div>
</template>
<script>
import {userService} from '#/service'
import {Toast} from 'mint-ui';
export default {
  props: ['id'],
  data() {
    return {
      open: true,
      openAn: false,
      rotateAn: false,
    }
  },
  methods: {
    initLottery () {
      this.$nextTick(async () => {
        let res = await userService.getLottery({
          params:{
            lotteryId: this.id
          }
        })
        if(res.data){
          Toast(res.data);
        }
      })
    },
    closePacket () {
      this.openAn = false;
      setTimeout(() => {
        this.$emit('closePacket');
      }, 1000)
    },
    openPacket () {
      this.rotateAn = true;
      this.initLottery();
      setTimeout(() => {
        this.openAn = true;
      }, 1500)
      setTimeout(() => {
        this.rotateAn = false;
        this.open = false
      }, 3000)
    }
  }
}
</script>
<style lang="less">
.will-packet {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  .will-packet__bg {
    position: absolute;
    left: 0;
    z-index: 2;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5)
  }
  .will-packet-top {
    width: 100%;
    height: 230px;
    overflow: hidden;
    background: #d85940;
    color: #f2bd91;
    .will-packet__head {
      width: 100%;
      height: 60px;
      margin-top: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 50px;
        height: 50px;
        border-radius: 5px;
        // border: 1px solid #fff;
      }
    }
    .will-packet__name {
      font-size: 20px;
      text-align: center;
      margin: 10px 0;
    }
    .will-packet__p {
      font-size: 14px;
      text-align: center;
    }
    .will-packet__title {
      font-size: 25px;
      margin: 20px 0;
      text-align: center;
    }
  }
  .will-packet__animation {
    width: 310px;
    height: 100px;
    position: absolute;
    top: 180px;
    .will-packet__an__top {
      width: 100%;
      height: 50px;
      display: flex;
      align-items: flex-end;
      .will-packet__an__inner {
        width: 100%;
        height: 0px;
        border-top-left-radius:150px 50px;
        border-top-right-radius:150px 50px;
        border-bottom-left-radius:0;
        border-bottom-right-radius:0;
        background: #cd523d;
        // animation: arcanimateTop 0.3s;

        &.arcanimateTop {
          animation: arcanimateTop 0.3s;
          animation-fill-mode: forwards;
          animation-delay: 0.2s;
        }
      }
    }
    .will-packet__an__bottom {
      width: 100%;
      height: 50px;
      border-top-left-radius:0;
      border-top-right-radius:0;
      border-bottom-left-radius:150px 50px;
      border-bottom-right-radius:150px 50px;
      background: #d85940;
      box-shadow: 0 1px 2px 0px #a13625;
      transform-origin: bottom;
      // animation: arcanimateBottom 0.3s;
      &.arcanimateBottom {
        animation: arcanimateBottom 0.3s;
        animation-fill-mode: forwards;
      }
    }
  }
  .will-packet__open {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    top: 235px;
    left: 50%;
    margin-left: -45px;
    border-radius: 100%;
    width: 90px;
    height: 90px;
    font-size: 40px;
    background: #ddbc84;
    border: 1px solid #c3abab;
    box-shadow: 0 0 0px 5px #ddbc84;
    color: #413f3d;
    // animation: rotateAn 2s;
    transform-origin: center center;
    &.rotateAn {
      animation: rotateAn 2s;
      animation-timing-function:cubic-bezier(.1,.86,.59,1.01);
    }
  }
  .will-packet__content {
    position: absolute;
    width: 310px;
    height: 410px;
    z-index: 3;
    border-radius: 5px;
    background: #cd523d;
    .close {
      color: #ffffff;
      position: absolute;
      top: 5px;
      right: 8px;
      font-size: 20px;
    }
  }
}

@keyframes rotateAn {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(720deg);
  }
}

@keyframes arcanimateTop {
  0% {
    height: 0;
    border-radius: 0;
  }
  100% {
    height: 50px;
    border-top-left-radius:150px 50px;
    border-top-right-radius:150px 50px;
    border-bottom-left-radius:0;
    border-bottom-right-radius:0;
  }
}
@keyframes arcanimateBottom {
  0% {
    height: 50px;
  }
  100% {
    height: 0;
    border-radius: 0;
  }
}
</style>
